import React, { Component } from 'react';
import { View,Text } from 'react-native';
import {ScaledSheet} from 'react-native-size-matters';
import PropTypes from 'prop-types';
import {klineApi} from '../../api/Kline'

class DetailKlineWrapper extends Component {
  state ={
    isLoading: true
  }
  getData =() =>{
    const { baseCurrency,
      quoteCurrency,
      exchangeName,
    } = this.props.data;
    const period = '15min';
    console.log('get data',baseCurrency);
    if (!baseCurrency) {
      return;
    }
    klineApi({
      baseCurrency,
      quoteCurrency,
      exchangeName,
      period: period === '1h'? '60min': period,
      to: parseInt(+ new Date() / 1000, 10),
      from: 0,
    }).then(res =>{
      console.log(res.data);
      if (res.success) {
        this.setState({
          isLoading:false,
          dataList: res.data
        })
      } else {
        this.setState({
          isLoading:false
        })
      }
    })
  }
  componentDidMount(){
    console.log('DetailKlineWrapper render')
    this.getData();
  }
  componentWillReceiveProps(nextProps){
    setTimeout(() => {
      this.getData();
    }, 0);
  }
  render() {
    const { baseCurrency,
      quoteCurrency,
      exchangeName,
    } = this.props.data;
    console.log('DetailKlineWrapper',baseCurrency)
    // const {maxPrcie,minPrice,newPrice,marketValue,percentChange24h,volume24h,turnoverRate} = this.props.data;
    return (
      <View style={styles.container}>
       <Text>
         kline
       </Text>
      </View>
    );
  }
}

const styles = ScaledSheet.create({
  container: {
    flexDirection: 'row',
    backgroundColor:'#fff',
    marginBottom: '7@s'
  },
  item:{
    flex: 1
  }
});

DetailKlineWrapper.propTypes = {
  data: PropTypes.object.isRequired
}
export default DetailKlineWrapper;
